/**
 * 
 */
package com.ingesup.services;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.ingesup.entities.Contact;

/**
 * @author FDEJEAN
 *
 */
public class ContactServiceTest {

	private static ContactService service;
	private static Contact user;
	
	@Before
	public void beforeTest() {
		service = new ContactServiceImpl();		
	}
	
	/**
	 * Test method for {@link com.ingesup.services.ContactServiceImpl#createContact(com.ingesup.entities.Contact)}.
	 */
	@Test
	public void testCreateContact() {
		Contact temp = new Contact();
		temp.setNom("wistiti");
		temp.setAdresseMail("florian.dejean@gmail.com");
		Contact temp2 = service.createContact(temp);
		assertNotNull(temp2);
		assertTrue(temp2.getId() > 0);
	}

	/**
	 * Test method for {@link com.ingesup.services.ContactServiceImpl#getListContact()}.
	 */
	@Test
	public void testGetListContact() {
		List<Contact> tempList = new ArrayList<Contact>();
		tempList = service.getListContact();
		assertEquals(1, tempList.size());
		user = tempList.get(0);
	}
	
	/**
	 * Test method for {@link com.ingesup.services.ContactServiceImpl#getContact(long)}.
	 */
	@Test
	public void testGetContact() {
		Contact temp = service.getContact(user.getId());
		assertNotNull(temp);
		assertNotNull(temp.getNom());
	}

	/**
	 * Test method for {@link com.ingesup.services.ContactServiceImpl#updateContact(com.ingesup.entities.Contact)}.
	 */
	@Test
	public void testUpdateContact() {
		Contact temp = service.getContact(user.getId());
		temp.setNom("Nounouille");
		service.updateContact(temp);
		
		temp = service.getContact(user.getId());
		assertEquals("Nounouille", temp.getNom());
	}

	/**
	 * Test method for {@link com.ingesup.services.ContactServiceImpl#deleteContact(com.ingesup.entities.Contact)}.
	 */
	@Test
	public void testDeleteContact() {
		service.deleteContact(user);
		assertEquals(0, service.getListContact().size());
	}
}
